From 92edf3bde7888b9d0ded7c047f9311405f7901b5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Fri, 26 Aug 2005 13:44:02 +0000 Subject: [PATCH] added format.bytes_per_pixel s/bands/components/ --- ChangeLog | 10 ++++++++ babl/babl-classes.h | 3 ++- babl/babl-format.c | 37 ++++++++++++++++++++++++---- babl/babl-image.c | 52 ++++++++++++++++++++-------------------- babl/babl-pixel-format.c | 37 ++++++++++++++++++++++++---- 5 files changed, 104 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22cf7dc..38557b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-08-25 Øyvind Kolås + + * babl/babl-classes.h: + BablFormat: added .bytes_per_pixel + BablImage: s/bands/components/ + * babl/babl-conversion.c: s/bands/components/ + * babl/babl-image.c: s/bands/components/ + * babl/babl-pixel-format.c: (format_new) check if provided pixel + format matches model. Calculate .bytes_per_pixel. + 2005-08-25 Øyvind Kolås * babl/babl-classes.h: diff --git a/babl/babl-classes.h b/babl/babl-classes.h index 5e11c8b..3811934 100644 --- a/babl/babl-classes.h +++ b/babl/babl-classes.h @@ -201,6 +201,7 @@ typedef struct BablType **type; BablSampling **sampling; BablModel *model; + int bytes_per_pixel; int planar; } BablFormat; @@ -209,7 +210,7 @@ typedef struct BablInstance instance; BablFormat *format; /*< (if known) */ BablModel *model; /*< (always known) */ - int bands; + int components; BablComponent **component; BablSampling **sampling; BablType **type; diff --git a/babl/babl-format.c b/babl/babl-format.c index fa0a9b4..fe3406d 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -49,6 +49,27 @@ format_new (const char *name, { Babl *babl; + { + int i; + /* i is desintation position */ + for (i=0 ; icomponents; i++) + { + int j; + + for (j=0;jcomponent[i]) + goto component_found; + } + babl_log ("%s(): matching source component for %s in model %s not found", + __FUNCTION__, + model->component[i]->instance.name, model->instance.name); + exit (-1); + component_found: + ; + } + } + /* allocate all memory in one chunk */ babl = babl_malloc (sizeof (BablFormat) + strlen (name) + 1 + @@ -58,25 +79,33 @@ format_new (const char *name, sizeof (int) * (components) + sizeof (int) * (components)); + babl->format.from = NULL; + babl->format.to = NULL; babl->format.component = ((void *)babl) + sizeof (BablFormat); babl->format.type = ((void *)babl->format.component) + sizeof (BablComponent*) * (components); babl->format.sampling = ((void *)babl->format.type) + sizeof (BablType*) * (components); - babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (components); + babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (components); babl->class_type = BABL_FORMAT; babl->instance.id = id; strcpy (babl->instance.name, name); + babl->format.model = model; babl->format.components = components; - babl->format.planar = planar; memcpy (babl->format.component, component, sizeof (BablComponent*) * components); memcpy (babl->format.type , type , sizeof (BablType*) * components); memcpy (babl->format.sampling , sampling , sizeof (BablSampling*) * components); - babl->format.from = NULL; - babl->format.to = NULL; + babl->format.planar = planar; + + babl->format.bytes_per_pixel = 0; + { + int i; + for (i=0;iformat.bytes_per_pixel += type[i]->bits/8; + } return babl; } diff --git a/babl/babl-image.c b/babl/babl-image.c index 1e36d96..7e02aab 100644 --- a/babl/babl-image.c +++ b/babl/babl-image.c @@ -31,7 +31,7 @@ static Babl * image_new (BablFormat *format, BablModel *model, - int bands, + int components, BablComponent **component, BablSampling **sampling, BablType **type, @@ -43,31 +43,31 @@ image_new (BablFormat *format, /* allocate all memory in one chunk */ babl = babl_malloc (sizeof (BablImage) + - sizeof (BablComponent*) * (bands) + - sizeof (BablSampling*) * (bands) + - sizeof (BablType*) * (bands) + - sizeof (void*) * (bands) + - sizeof (int) * (bands) + - sizeof (int) * (bands)); + sizeof (BablComponent*) * (components) + + sizeof (BablSampling*) * (components) + + sizeof (BablType*) * (components) + + sizeof (void*) * (components) + + sizeof (int) * (components) + + sizeof (int) * (components)); babl->image.component = ((void *)babl) + sizeof (BablImage); - babl->image.sampling = ((void *)babl->image.component) + sizeof (BablComponent*) * (bands); - babl->image.type = ((void *)babl->image.sampling) + sizeof (BablSampling*) * (bands); - babl->image.data = ((void *)babl->image.type) + sizeof (BablType*) * (bands); - babl->image.pitch = ((void *)babl->image.data) + sizeof (void*) * (bands); - babl->image.stride = ((void *)babl->image.pitch) + sizeof (int) * (bands); - - babl->class_type = BABL_IMAGE; - babl->instance.id = 0; - babl->instance.name = "slaritbartfast"; - - babl->image.format = format; - babl->image.model = model; - babl->image.bands = bands; - memcpy (babl->image.component, component, bands * sizeof(void*)); - memcpy (babl->image.type, type, bands * sizeof(void*)); - memcpy (babl->image.data, data, bands * sizeof(void*)); - memcpy (babl->image.pitch, pitch, bands * sizeof(int)); - memcpy (babl->image.stride, stride, bands * sizeof(int)); + babl->image.sampling = ((void *)babl->image.component) + sizeof (BablComponent*) * (components); + babl->image.type = ((void *)babl->image.sampling) + sizeof (BablSampling*) * (components); + babl->image.data = ((void *)babl->image.type) + sizeof (BablType*) * (components); + babl->image.pitch = ((void *)babl->image.data) + sizeof (void*) * (components); + babl->image.stride = ((void *)babl->image.pitch) + sizeof (int) * (components); + + babl->class_type = BABL_IMAGE; + babl->instance.id = 0; + babl->instance.name = "slaritbartfast"; + babl->image.format = format; + babl->image.model = model; + babl->image.components = components; + + memcpy (babl->image.component, component, components * sizeof(void*)); + memcpy (babl->image.type, type, components * sizeof(void*)); + memcpy (babl->image.data, data, components * sizeof(void*)); + memcpy (babl->image.pitch, pitch, components * sizeof(int)); + memcpy (babl->image.stride, stride, components * sizeof(int)); return babl; } @@ -152,7 +152,7 @@ babl_image (void *first, { va_list varg; Babl *babl; - int components = 0; + int components= 0; BablFormat *format = NULL; BablModel *model = NULL; BablComponent *component [BABL_MAX_COMPONENTS]; diff --git a/babl/babl-pixel-format.c b/babl/babl-pixel-format.c index fa0a9b4..fe3406d 100644 --- a/babl/babl-pixel-format.c +++ b/babl/babl-pixel-format.c @@ -49,6 +49,27 @@ format_new (const char *name, { Babl *babl; + { + int i; + /* i is desintation position */ + for (i=0 ; icomponents; i++) + { + int j; + + for (j=0;jcomponent[i]) + goto component_found; + } + babl_log ("%s(): matching source component for %s in model %s not found", + __FUNCTION__, + model->component[i]->instance.name, model->instance.name); + exit (-1); + component_found: + ; + } + } + /* allocate all memory in one chunk */ babl = babl_malloc (sizeof (BablFormat) + strlen (name) + 1 + @@ -58,25 +79,33 @@ format_new (const char *name, sizeof (int) * (components) + sizeof (int) * (components)); + babl->format.from = NULL; + babl->format.to = NULL; babl->format.component = ((void *)babl) + sizeof (BablFormat); babl->format.type = ((void *)babl->format.component) + sizeof (BablComponent*) * (components); babl->format.sampling = ((void *)babl->format.type) + sizeof (BablType*) * (components); - babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (components); + babl->instance.name = ((void *)babl->format.sampling) + sizeof (BablSampling*) * (components); babl->class_type = BABL_FORMAT; babl->instance.id = id; strcpy (babl->instance.name, name); + babl->format.model = model; babl->format.components = components; - babl->format.planar = planar; memcpy (babl->format.component, component, sizeof (BablComponent*) * components); memcpy (babl->format.type , type , sizeof (BablType*) * components); memcpy (babl->format.sampling , sampling , sizeof (BablSampling*) * components); - babl->format.from = NULL; - babl->format.to = NULL; + babl->format.planar = planar; + + babl->format.bytes_per_pixel = 0; + { + int i; + for (i=0;iformat.bytes_per_pixel += type[i]->bits/8; + } return babl; } -- 2.30.2